package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appmarket.service.store.awk.bean.NarrowAppListCardBean;
import com.huawei.appmarket.service.store.awk.bean.NarrowAppListCardBean.TagInfo;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.cgy;
import o.cgz;
import o.chy;
import o.dni;
import o.eib;
import o.eqx;
import o.evx;
import o.ewm.d;
import o.ewm.h;
import o.ewm.j;

public class BaseApplistCard extends BaseDistCard {
    private static final Float ˋ = Float.valueOf(0.38f);
    private RelativeLayout ʻ;
    private ImageView ʻॱ;
    private LinearLayout ʼ;
    private LinearLayout ʽ;
    private TextView ˊॱ;
    private View ˋॱ;
    private RelativeLayout ˏॱ;
    private TextView ͺ;
    private TextView ॱˊ;
    private TextView ॱˋ;
    private ImageView ॱˎ;
    private chy ॱॱ;
    private ImageView ॱᐝ;
    private LinearLayout ᐝ;
    private ArrayList<String> ᐝॱ = new ArrayList();

    public BaseApplistCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        this.ʻ = (RelativeLayout) view.findViewById(j.ॱᐩ);
        ˏ((ImageView) view.findViewById(j.ʻˊ));
        ॱ((TextView) view.findViewById(j.ʽ));
        ˋ((DownloadButton) view.findViewById(j.ᵣ));
        this.ᐝ = (LinearLayout) view.findViewById(j.ʼߵ);
        this.ʽ = (LinearLayout) view.findViewById(j.ˆˊ);
        this.ʼ = (LinearLayout) view.findViewById(j.ʼߴ);
        this.ˏॱ = (RelativeLayout) view.findViewById(j.ʻٴ);
        this.ॱˊ = (TextView) view.findViewById(j.ʹʼ);
        this.ͺ = (TextView) view.findViewById(j.ˊﾞ);
        this.ˊॱ = (TextView) view.findViewById(j.ˏﹺ);
        this.ॱˎ = (ImageView) view.findViewById(j.ˎᵢ);
        this.ʻॱ = (ImageView) view.findViewById(j.ˏᵢ);
        this.ॱᐝ = (ImageView) view.findViewById(j.ˎﹺ);
        this.ॱˋ = (TextView) view.findViewById(j.ㆍʼ);
        this.ˋॱ = view.findViewById(j.ᐧᐝ);
        ॱॱ();
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        NarrowAppListCardBean narrowAppListCardBean = (NarrowAppListCardBean) cardBean;
        this.ͺ.setText(narrowAppListCardBean.ˎͺ());
        if (ˊᐝ()) {
            this.ˋॱ.setVisibility(0);
        } else {
            this.ˋॱ.setVisibility(4);
        }
        ˋ(narrowAppListCardBean);
        this.ᐝॱ.clear();
        if (narrowAppListCardBean.ꞌ() == 0) {
            ˊ(narrowAppListCardBean.ʻᐝ());
        } else if (narrowAppListCardBean.ꞌ() == 3) {
            ॱ(narrowAppListCardBean.ﹳ());
        } else if (narrowAppListCardBean.ꞌ() == 5) {
            ˏ(narrowAppListCardBean.ʹ());
        } else if (narrowAppListCardBean.ꞌ() == 7) {
            ˎ(narrowAppListCardBean.ʻᐝ());
        } else {
            ʼ();
        }
    }

    public void w_() {
        eqx.ˏ(this.ʽॱ, this.ˊᐝ.ॱˌ(), "app_default_icon");
    }

    private void ˋ(NarrowAppListCardBean narrowAppListCardBean) {
        if (narrowAppListCardBean.ˋˋ() != null) {
            int ˏॱ = ˏॱ();
            if (narrowAppListCardBean.ˋˋ().ˊ() != null) {
                ˏॱ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˉ);
            }
            if (narrowAppListCardBean.ˋˋ().ॱ() != null) {
                ˏॱ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˉ);
            }
            if (narrowAppListCardBean.ˋˋ().ˋ() != null) {
                ˏॱ -= this.ʼॱ.getResources().getDimensionPixelSize(d.ॱˉ);
            }
            ˊˋ().setMaxWidth(ˏॱ);
            if (narrowAppListCardBean.ˋˋ() != null) {
                ˊ(this.ॱˎ, narrowAppListCardBean.ˋˋ().ˊ());
                ˊ(this.ʻॱ, narrowAppListCardBean.ˋˋ().ॱ());
            }
            if (narrowAppListCardBean.ˋˋ() == null || TextUtils.isEmpty(narrowAppListCardBean.ˋˋ().ˋ())) {
                this.ॱᐝ.setVisibility(8);
                return;
            }
            this.ॱᐝ.setVisibility(0);
            eqx.ˏ(this.ॱᐝ, narrowAppListCardBean.ˋˋ().ˋ(), "iconflag");
        }
    }

    public ArrayList<String> ˊ() {
        ArrayList<String> arrayList = new ArrayList();
        if (ˋ() == null) {
            return arrayList;
        }
        arrayList.add(ˋ().ॱॱ() + "#$#" + ˋ().u_());
        Iterator it = this.ᐝॱ.iterator();
        while (it.hasNext()) {
            arrayList.add(((String) it.next()) + "#$#");
        }
        return arrayList;
    }

    public NarrowAppListCardBean ˋ() {
        if (this.ˊᐝ != null) {
            return (NarrowAppListCardBean) this.ˊᐝ;
        }
        return null;
    }

    private void ˊ(ImageView imageView, String str) {
        if (imageView != null) {
            if (dni.ˏ(str)) {
                imageView.setVisibility(8);
            } else {
                imageView.setVisibility(0);
            }
        }
    }

    private void ˏ(int i) {
        ((LayoutParams) this.ʽ.getLayoutParams()).addRule(3, i);
    }

    private void ˏ(String str) {
        this.ᐝ.setVisibility(0);
        this.ʼ.setVisibility(8);
        this.ˏॱ.setVisibility(0);
        this.ˊॱ.setVisibility(8);
        CharSequence charSequence = "";
        if (!TextUtils.isEmpty(str)) {
            float floatValue = Float.valueOf(str).floatValue();
            charSequence = String.format(Locale.ENGLISH, "%.1f", new Object[]{Float.valueOf(floatValue)});
        }
        this.ॱˊ.setText(charSequence);
        ˏ(j.ʼߵ);
    }

    private void ॱ(String str) {
        this.ᐝ.setVisibility(8);
        this.ʼ.setVisibility(8);
        this.ˏॱ.setVisibility(8);
        this.ˊॱ.setVisibility(0);
        this.ˊॱ.setText(str);
        ˏ(j.ˏﹺ);
    }

    protected void ˎ(List<TagInfo> list) {
        this.ˏॱ.setVisibility(8);
        this.ᐝ.setVisibility(0);
        this.ʼ.setVisibility(0);
        this.ˊॱ.setVisibility(8);
        this.ʼ.removeAllViews();
        ˏ(j.ʼߵ);
        int ˏॱ = ˏॱ();
        if (list == null) {
            this.ʼ.setVisibility(8);
            return;
        }
        int i = 0;
        int i2 = 0;
        while (i < list.size()) {
            TagInfo tagInfo = (TagInfo) list.get(i);
            HwButton hwButton = (HwButton) LayoutInflater.from(this.ʼॱ).inflate(h.ᐝˈ, null);
            hwButton.setText(tagInfo.ˊ());
            hwButton.setPadding(this.ʼॱ.getResources().getDimensionPixelSize(d.ॱ), hwButton.getPaddingTop(), this.ʼॱ.getResources().getDimensionPixelSize(d.ॱ), hwButton.getPaddingBottom());
            ˋ(hwButton, tagInfo);
            int ॱ = ॱ(hwButton, (String) hwButton.getText());
            if (ॱ < this.ʼॱ.getResources().getDimensionPixelSize(d.ʽ)) {
                ॱ = this.ʼॱ.getResources().getDimensionPixelSize(d.ʽ);
            }
            ॱ += i2;
            ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, this.ʼॱ.getResources().getDimensionPixelSize(d.ˊ));
            if (ॱ < ˏॱ || i == 0) {
                if (ˏॱ - ॱ > this.ʼॱ.getResources().getDimensionPixelSize(d.ˊʽ)) {
                    layoutParams.setMarginEnd(this.ʼॱ.getResources().getDimensionPixelSize(d.ˊʽ));
                }
                hwButton.setLayoutParams(layoutParams);
                this.ʼ.addView(hwButton);
                if (!TextUtils.isEmpty(tagInfo.ˏ())) {
                    this.ᐝॱ.add(tagInfo.ˏ());
                }
                i++;
                i2 = ॱ + this.ʼॱ.getResources().getDimensionPixelSize(d.ˊʽ);
            } else {
                return;
            }
        }
    }

    private void ˊ(List<TagInfo> list) {
        this.ˏॱ.setVisibility(8);
        this.ᐝ.setVisibility(0);
        this.ʼ.setVisibility(0);
        this.ˊॱ.setVisibility(8);
        this.ʼ.removeAllViews();
        ˏ(j.ʼߵ);
        if (list != null && list.size() > 0) {
            TagInfo tagInfo = (TagInfo) list.get(0);
            HwButton hwButton = (HwButton) LayoutInflater.from(this.ʼॱ).inflate(h.ᐝˈ, null);
            hwButton.setText(tagInfo.ˊ());
            ˋ(hwButton, tagInfo);
            hwButton.setPadding(this.ʼॱ.getResources().getDimensionPixelSize(d.ॱ), hwButton.getPaddingTop(), this.ʼॱ.getResources().getDimensionPixelSize(d.ॱ), hwButton.getPaddingBottom());
            this.ʼ.addView(hwButton);
            if (!TextUtils.isEmpty(tagInfo.ˏ())) {
                this.ᐝॱ.add(tagInfo.ˏ());
            }
        }
    }

    private void ˋ(HwButton hwButton, final TagInfo tagInfo) {
        if (TextUtils.isEmpty(tagInfo.ˏ())) {
            hwButton.setAlpha(ˋ.floatValue());
            hwButton.setOnClickListener(null);
            return;
        }
        hwButton.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ BaseApplistCard ॱ;

            public void onClick(View view) {
                if (this.ॱ.ॱॱ != null) {
                    String ॱॱ = this.ॱ.ˌ().ॱॱ();
                    this.ॱ.ˌ().ॱ(tagInfo.ˏ());
                    this.ॱ.ॱॱ.ˏ(0, this.ॱ);
                    this.ॱ.ˌ().ॱ(ॱॱ);
                }
            }
        });
    }

    private void ʼ() {
        this.ˏॱ.setVisibility(8);
        this.ᐝ.setVisibility(0);
        this.ʼ.setVisibility(0);
        this.ˊॱ.setVisibility(8);
        this.ʼ.removeAllViews();
        ˏ(j.ʼߵ);
    }

    public void ॱ(final chy o_chy) {
        if (o_chy != null) {
            this.ॱॱ = o_chy;
            this.ʻ.setOnClickListener(new evx(this) {
                final /* synthetic */ BaseApplistCard ˎ;

                public void ˋ(View view) {
                    o_chy.ˏ(0, this.ˎ);
                }
            });
        }
    }

    private void ॱॱ() {
        azb.ʻ(this.ˋॱ);
    }

    private int ॱ(TextView textView, String str) {
        if (textView == null || cgy.ˎ(str)) {
            return 0;
        }
        return (((int) textView.getPaint().measureText(str)) + textView.getPaddingLeft()) + textView.getPaddingRight();
    }

    private int ˏॱ() {
        return (((((ˎ() - ʻ()) - this.ʼॱ.getResources().getDimensionPixelSize(d.ᐝ)) - this.ʼॱ.getResources().getDimensionPixelSize(d.ͺ)) - this.ʼॱ.getResources().getDimensionPixelSize(d.ˋ)) - this.ʼॱ.getResources().getDimensionPixelSize(d.ᐝ)) - ᐝ();
    }

    protected int ˎ() {
        int ॱˎ = eib.ॱˎ();
        int ॱ = azb.ॱ(this.ʼॱ);
        if (ॱˎ == 0) {
            ॱˎ = 1;
        }
        return ॱ / ॱˎ;
    }

    protected int ʻ() {
        return azb.ˊ(this.ʼॱ);
    }

    protected int ᐝ() {
        return azb.ˏ(this.ʼॱ);
    }

    public boolean ˋ(TextView textView, String str) {
        if (textView == null) {
            return false;
        }
        if (this.ˊᐝ instanceof BaseCardBean) {
            BaseCardBean baseCardBean = (BaseCardBean) this.ˊᐝ;
            if (TextUtils.isEmpty(str) || (baseCardBean.ॱʾ() && !TextUtils.isEmpty(baseCardBean.showDetailUrl_))) {
                textView.setVisibility(8);
                return false;
            }
        }
        return super.ˋ(textView, str);
    }
}
